local extension = Package("skrenjie")
extension.extensionName = "jilvRem"

local U = require "packages/utility/utility"

Fk:loadTranslationTable{
  ["skrenjie"] = "极略三国-人杰",
  ["sk_sp"] = "极略SP",
}

local luzhi = General(extension, "sk__luzhi", "qun", 3)
local sk__jinglun = fk.CreateTriggerSkill{
  name = "sk__jinglun",
  anim_type = "drawcard",
  events = {fk.CardUsing, fk.CardResponding},
  can_trigger = function(self, event, target, player, data)
    if player:hasSkill(self) and data.responseToEvent and player:usedSkillTimes(self.name, Player.HistoryTurn) == 0 then
      if target == player then
        return data.responseToEvent.from ~= player.id and data.toCard and
          player.room:getCardArea(data.toCard) == Card.Processing
      else
        return data.responseToEvent.from == player.id and data.responseToEvent.card and
          player.room:getCardArea(data.card) == Card.Processing
      end
    end
  end,
  on_cost = function(self, event, target, player, data)
    local card
    if target == player then
      card = data.toCard
    else
      card = data.card
    end
    return player.room:askForSkillInvoke(player, self.name, nil, "#sk__jinglun-invoke:::"..card:toLogString())
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    if target == player then
      room:moveCardTo(data.toCard, Card.PlayerHand, player, fk.ReasonPrey, self.name, nil, true, player.id)
    else
      room:moveCardTo(data.card, Card.PlayerHand, player, fk.ReasonPrey, self.name, nil, true, player.id)
    end
  end,
}
local sk__ruzong = fk.CreateViewAsSkill{
  name = "sk__ruzong",
  pattern = "jink,nullification",
  prompt = "#sk__ruzong",
  card_filter = function(self, to_select, selected,player)
    if #selected == 0 then
      local c = Fk:getCardById(to_select)
      local card
      if c.trueName == "nullification" then
        card = Fk:cloneCard("jink")
      elseif c.name == "jink" then
        card = Fk:cloneCard("nullification")
      else
        return false
      end
      return (Fk.currentResponsePattern == nil and player:canUse(card)) or
        (Fk.currentResponsePattern and Exppattern:Parse(Fk.currentResponsePattern):match(card))
    end
  end,
  view_as = function(self, cards)
    if #cards ~= 1 then return end
    local c = Fk:getCardById(cards[1])
    local card
    if c.trueName == "nullification" then
      card = Fk:cloneCard("jink")
    elseif c.name == "jink" then
      card = Fk:cloneCard("nullification")
    end
    card.skillName = self.name
    card:addSubcard(cards[1])
    return card
  end,
}
luzhi:addSkill(sk__jinglun)
luzhi:addSkill(sk__ruzong)
Fk:loadTranslationTable{
  ["sk__luzhi"] = "卢植",
  ["#sk__luzhi"] = "国之桢干",

  ["sk__jinglun"] = "经纶",
  [":sk__jinglun"] = "每回合限一次，当你响应其他角色使用的牌时，或当其他角色响应你使用的牌时，你可以获得其使用或响应的牌。",
  ["sk__ruzong"] = "儒宗",
  [":sk__ruzong"] = "你可以将【闪】当【无懈可击】、【无懈可击】当【闪】使用或打出。",
  ["#sk__jinglun-invoke"] = "经纶：是否获得%arg？",
  ["#sk__ruzong"] = "儒宗：你可以将【闪】当【无懈可击】、【无懈可击】当【闪】使用或打出",

  ["$sk__jinglun1"] = "有伊尹之志则可。",
  ["$sk__jinglun2"] = "无伊尹之志，则篡也！",
  ["$sk__ruzong"] = "儒之典籍，国之重器。",
  ["~sk__luzhi"] = "",
}

local mifuren = General(extension, "sk__mifuren", "shu", 3, 3, General.Female)
local sk__guixiu = fk.CreateTriggerSkill{
  name = "sk__guixiu",
  anim_type = "defensive",
  events = {fk.EventPhaseChanging},
  can_trigger = function(self, event, target, player, data)
    if target == player and player:hasSkill(self) and data.to == Player.Discard then
      return #player.room.logic:getEventsOfScope(GameEvent.ChangeHp, 1, function (e)
        local damage = e.data[5]
        if damage and player == damage.from then
          return true
        end
      end, Player.HistoryTurn) == 0
    end
  end,
  on_use = function(self, event, target, player, data)
    player:drawCards(1, self.name)
    return true
  end,
}
local sk__cunsi = fk.CreateTriggerSkill{
  name = "sk__cunsi",
  anim_type = "support",
  events = {fk.Death},
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(self, false, true)
  end,
  on_cost = function(self, event, target, player, data)
    local to = player.room:askForChoosePlayers(player, table.map(player.room.alive_players, Util.IdMapper), 1, 1,
      "#sk__cunsi-choose", self.name, true)
    if #to > 0 then
      self.cost_data = to[1]
      return true
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local to = room:getPlayerById(self.cost_data)
    room:handleAddLoseSkills(to, "sk__yongjue", nil, true, false)
    if not to.dead and not player:isAllNude() then
      to:addToPile(self.name, player:getCardIds("hej"), false, self.name, player.id)
    end
  end,
}
local sk__yongjue = fk.CreateTriggerSkill{
  name = "sk__yongjue",
  anim_type = "offensive",
  frequency = Skill.Compulsory,
  events = {fk.DamageCaused, fk.Death},
  can_trigger = function(self, event, target, player, data)
    if player:hasSkill(self) then
      if event == fk.DamageCaused then
        return target == player and not data.chain and data.card and data.card.trueName == "slash"
      else
        return data.damage and data.damage.from and data.damage.from == player and #player:getPile("sk__cunsi") > 0
      end
    end
  end,
  on_use = function(self, event, target, player, data)
    if event == fk.DamageCaused then
      data.damage = data.damage + 1
    else
      player.room:moveCardTo(player:getPile("sk__cunsi"), Card.PlayerHand, player, fk.ReasonPrey, self.name, nil, false, player.id)
    end
  end,
}
mifuren:addSkill(sk__guixiu)
mifuren:addSkill(sk__cunsi)
mifuren:addRelatedSkill(sk__yongjue)
Fk:loadTranslationTable{
  ["sk__mifuren"] = "糜夫人",
  ["#sk__mifuren"] = "青莲疏影",

  ["sk__guixiu"] = "闺秀",
  [":sk__guixiu"] = "弃牌阶段开始前，若你本回合未造成过伤害，你可以跳过弃牌阶段并摸一张牌。",
  ["sk__cunsi"] = "存嗣",
  [":sk__cunsi"] = "当你死亡时，你可以令一名角色获得〖勇决〗，将你区域内所有牌置于该角色的武将牌上。",
  ["sk__yongjue"] = "勇决",
  [":sk__yongjue"] = "锁定技，你使用【杀】造成伤害+1；当你杀死一名角色后，你获得〖存嗣〗移出游戏的牌。",
  ["#sk__cunsi-choose"] = "存嗣：你可以令一名角色获得“勇决”（【杀】伤害+1，杀死角色后获得你的牌）",

  ["$sk__guixiu"] = "袅娜少女羞，岁月无忧愁。",
  ["$sk__cunsi"] = "希望你能像你父亲一样。",
  ["$sk__yongjue1"] = "身负我命，何惧天下！",
  ["$sk__yongjue2"] = "这样，我就怕了吗！",
  ["$sk__yongjue3"] = "身负我命，何惧天下！",
  ["$sk__yongjue4"] = "这样，我就怕了吗！",
  ["~sk__mifuren"] = "我意已决，将军快走吧！",
}

local xizhicai = General(extension, "sk__xizhicai", "wei", 3)
local sk__tiance = fk.CreateTriggerSkill{
  name = "sk__tiance",
  anim_type = "support",
  events = {fk.EventPhaseStart},
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(self) and player.phase == Player.Start
  end,
  on_cost = function(self, event, target, player, data)
    local room = player.room
    local to = room:askForChoosePlayers(player, table.map(room.alive_players, Util.IdMapper), 1, 1,
      "#sk__tiance-choose", self.name, true)
    if #to > 0 then
      self.cost_data = to[1]
      return true
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local to = room:getPlayerById(self.cost_data)
    local judge = {
      who = target,
      reason = self.name,
      pattern = ".",
    }
    room:judge(judge)
    if to.dead then return end
    if judge.card.suit ~= Card.NoSuit then
      local cards = table.filter(room.draw_pile, function (id)
        return Fk:getCardById(id).suit == judge.card.suit
      end)
      table.insertTable(cards, table.filter(room.discard_pile, function (id)
        return Fk:getCardById(id).suit == judge.card.suit
      end))
      for _, p in ipairs(room:getOtherPlayers(to)) do
        table.insertTable(cards, table.filter(p:getCardIds("he"), function (id)
          return Fk:getCardById(id).suit == judge.card.suit
        end))
      end
      if #cards > 0 then
        room:moveCardTo(table.random(cards, 2), Card.PlayerHand, to, fk.ReasonPrey, self.name, nil, false, to.id)
      end
    end
    if not player.dead and event == fk.Damaged and data.card and data.card.color == judge.card.color then
      self.cost_data = "sk__jiexin"
    end
  end,
}
local sk__jiexin = fk.CreateTriggerSkill{
  name = "sk__jiexin",
  anim_type = "masochism",
  events = {fk.Damaged},
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(self)
  end,
  on_cost = function(self, event, target, player, data)
    return player.room:askForSkillInvoke(player, self.name) and
      sk__tiance:cost(event, target, player, {extra_data = self.name})
  end,
  on_use = function(self, event, target, player, data)
    player.room:useSkill(player, sk__tiance, function()
      return sk__tiance:use(event, target, player, data)
    end)
    if not player.dead and sk__tiance.cost_data == self.name then
      sk__tiance:trigger(event, target, player, data)
    end
  end,
}
xizhicai:addSkill(sk__tiance)
xizhicai:addSkill(sk__jiexin)
Fk:loadTranslationTable{
  ["sk__xizhicai"] = "戏志才",
  ["#sk__xizhicai"] = "",

  ["sk__tiance"] = "天策",
  [":sk__tiance"] = "准备阶段，你可以令一名角色判定，令其从牌堆、弃牌堆或其他角色手牌或装备区随机获得共计两张与判定结果花色相同的牌。",
  ["sk__jiexin"] = "竭心",
  [":sk__jiexin"] = "当你受到伤害后，你可以发动〖天策〗，然后若此次〖天策〗判定结果与对你造成伤害的牌颜色相同，你可以再次发动〖天策〗。",
  ["#sk__tiance-choose"] = "天策：你可以令一名角色判定，其随机获得两张与判定结果花色相同的牌",

  ["$sk__tiance1"] = "天衍四九，人遁其一。",
  ["$sk__tiance2"] = "开云见日，势必争晖。",
  ["$sk__jiexin1"] = "春蚕至死，蜡炬成灰。",
  ["$sk__jiexin2"] = "愿为主公，呕心沥血。",
  ["~sk__xizhicai"] = "人算不如天算……咳咳咳……",
}

local zhangliang = General(extension, "sk__zhangliang", "qun", 3)
local sk__jijun = fk.CreateActiveSkill{
  name = "sk__jijun",
  anim_type = "special",
  min_card_num = 1,
  target_num = 0,
  prompt = "#sk__jijun",
  derived_piles = "sk__zhangliang__bing",
  expand_pile = "sk__zhangliang__bing",
  can_use = function(self, player)
    return player:usedSkillTimes(self.name, Player.HistoryPhase) == 0
  end,
  target_filter = Util.FalseFunc,
  card_filter = function(self, to_select, selected)
    return #selected < 4 and Fk:currentRoom():getCardArea(to_select) == Player.Hand and
      table.every(selected, function(id)
        return Fk:getCardById(to_select).suit ~= Fk:getCardById(id).suit
      end)
  end,
  on_use = function(self, room, effect)
    local player = room:getPlayerById(effect.from)
    local cards = table.filter(player:getPile("sk__zhangliang__bing"), function(id)
      return table.find(effect.cards, function(id2)
        return Fk:getCardById(id).suit == Fk:getCardById(id2).suit and Fk:getCardById(id).suit ~= Card.NoSuit
      end)
    end)
    if #cards == 0 then
      player:addToPile("sk__zhangliang__bing", effect.cards, true, self.name, player.id)
    else
      U.swapCardsWithPile(player, effect.cards, cards, self.name, "sk__zhangliang__bing", true, player.id)
    end
    if player.dead then return end
    U.askForUseVirtualCard(room, player, U.getAllCardNames("b"), nil, self.name, "#sk__jijun-use", true, true, true, nil)
  end,
}
local sk__fangtong = fk.CreateTriggerSkill{
  name = "sk__fangtong",
  anim_type = "drawcard",
  frequency = Skill.Compulsory,
  events = {fk.EventPhaseStart},
  can_trigger = function(self, event, target, player, data)
    if target == player and player:hasSkill(self) and player.phase == Player.Finish then
      local n = 0
      for _, id in ipairs(player:getPile("sk__zhangliang__bing")) do
        n = n + Fk:getCardById(id).number
      end
      n = math.min(n // 9, 4)
      if player:getHandcardNum() < n then
        self.cost_data = n - player:getHandcardNum()
        return true
      end
    end
  end,
  on_use = function(self, event, target, player, data)
    player:drawCards(self.cost_data, self.name)
  end,

  refresh_events = {fk.AfterCardsMove},
  can_refresh = function (self, event, target, player, data)
    for _, move in ipairs(data) do
      if move.to and move.to == player.id and move.toArea == Card.PlayerSpecial and move.specialName == "sk__zhangliang__bing" then
        return true
      end
      if move.from and move.from == player.id then
        for _, info in ipairs(move.moveInfo) do
          if info.fromArea == Card.PlayerSpecial and info.fromSpecialName == "sk__zhangliang__bing" then
            return true
          end
        end
      end
    end
  end,
  on_refresh = function (self, event, target, player, data)
    local n = 0
    for _, id in ipairs(player:getPile("sk__zhangliang__bing")) do
      n = n + Fk:getCardById(id).number
    end
    n = math.min(n // 9, 4)
    local all_skills = {"leiji", "sk__zhoufu", "sk__shendao", "sk__biantian"}
    local mark = player:getTableMark(self.name)
    local skills = {}
    for i = 1, 4, 1 do
      local s = all_skills[i]
      if i <= n and not player:hasSkill(s, true) and not table.contains(mark, s) then
        table.insert(skills, s)
        table.insert(mark, s)
      elseif i > n and player:hasSkill(s, true) and table.contains(mark, s) then
        table.insert(skills, "-"..s)
        table.removeOne(mark, s)
      end
    end
    player.room:setPlayerMark(player, self.name, mark)
    player.room:handleAddLoseSkills(player, table.concat(skills, "|"), nil, false, true)
  end,
}
zhangliang:addSkill(sk__jijun)
zhangliang:addSkill(sk__fangtong)
zhangliang:addRelatedSkill("leiji")
zhangliang:addRelatedSkill("sk__zhoufu")
zhangliang:addRelatedSkill("sk__shendao")
zhangliang:addRelatedSkill("sk__biantian")
Fk:loadTranslationTable{
  ["sk__zhangliang"] = "张梁",
  ["#sk__zhangliang"] = "人公将军",

  ["sk__jijun"] = "集军",
  [":sk__jijun"] = "出牌阶段限一次，你可以将任意张花色各不相同的手牌置于你的武将牌上，称为“兵”（每种花色的“兵”至多一张），"..
  "或用手牌替换同花色的“兵”，若如此做，你可以视为使用一张任意基本牌（无距离和次数限制）。",
  ["sk__fangtong"] = "方统",
  [":sk__fangtong"] = "锁定技，若“兵”的点数之和不小于：<br>9，你视为拥有〖雷击〗；<br>18，你视为拥有〖咒缚〗；<br>"..
  "27，你视为拥有〖神道〗；<br>36，你视为拥有〖变天〗。<br>结束阶段，你将手牌摸至X张（X为你因〖方统〗获得的技能数）。",
  ["#sk__jijun"] = "集军：将任意张手牌置为“兵”，或用手牌替换同花色的“兵”",
  ["sk__zhangliang__bing"] = "兵",
  ["#sk__jijun-use"] = "集军：你可以视为使用一张任意基本牌（无距离次数限制）",

  ["$sk__jijun1"] = "呵呵呵呵，天下万民，皆可为我所用。",
  ["$sk__jijun2"] = "星星之火，亦可成燎原之势！",
  ["$sk__fangtong1"] = "黄巾三十六方，当一统天下！",
  ["$sk__fangtong2"] = "奉黄天之命，可统三十六方。",
  ["~sk__zhangliang"] = "黄天之道，吾已无颜相见……",
}

local caorui = General(extension, "sk__caorui", "wei", 3)
local sk__huituo_active = fk.CreateActiveSkill{
  name = "sk__huituo_active",
  card_num = 0,
  target_num = 1,
  interaction = function(self,player)
    local choices, all_choices = {}, {}
    for i = 1, 4, 1 do
      table.insert(all_choices, "sk__huituo"..i)
      if not table.contains(player:getTableMark("sk__huituo"), i) then
        table.insert(choices, "sk__huituo"..i)
      end
    end
    return UI.ComboBox {choices = choices, all_choices = all_choices}
  end,
  card_filter = Util.FalseFunc,
  target_filter =function (self, to_select, selected, selected_cards, card, extra_data, player)
    if #selected == 0 then
      local target = Fk:currentRoom():getPlayerById(to_select)
      if self.interaction.data == "sk__huituo1" then
        return target:isWounded()
      elseif self.interaction.data == "sk__huituo2" then
        return true
      elseif self.interaction.data == "sk__huituo3" then
        return target:hasEmptyEquipSlot()
      elseif self.interaction.data == "sk__huituo4" then
        return not target:hasSkill("sk__huituo", true)
      end
    end
  end,
}
local sk__huituo = fk.CreateTriggerSkill{
  name = "sk__huituo",
  anim_type = "support",
  events = {fk.TurnStart},
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(self) and #player:getTableMark(self.name) < 4
  end,
  on_cost = function (self, event, target, player, data)
    local _, dat = player.room:askForUseActiveSkill(player, "sk__huituo_active", "#sk__huituo-invoke", true, nil, false)
    if dat then
      self.cost_data = dat
      return true
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local to = room:getPlayerById(self.cost_data.targets[1])
    local choice = self.cost_data.interaction
    local mark = player:getTableMark(self.name)
    table.insert(mark, tonumber(choice[11]))
    room:setPlayerMark(player, self.name, mark)
    if choice == "sk__huituo1" then
      if not to:isWounded() then return end
      local n = to.hp
      for _, p in ipairs(room.alive_players) do
        if p.hp > n then
          n = p.hp
        end
      end
      n = n + 1
      room:recover{
        who = to,
        num = math.min(n - to.hp, to:getLostHp()),
        recoverBy = player,
        skillName = self.name,
      }
    elseif choice == "sk__huituo2" then
      local n = to:getHandcardNum()
      for _, p in ipairs(room.alive_players) do
        if p:getHandcardNum() > n then
          n = p:getHandcardNum()
        end
      end
      n = n + 1
      to:drawCards(n - to:getHandcardNum(), self.name)
    elseif choice == "sk__huituo3" then
      for _, slot in ipairs(to:getAvailableEquipSlots()) do
        if to.dead then return end
        local type = Util.convertSubtypeAndEquipSlot(slot)
        if #to:getEquipments(type) < #to:getAvailableEquipSlots(type) then
          local cards = table.filter(room.draw_pile, function(id)
            local card = Fk:getCardById(id)
            return card.sub_type == type and not to:isProhibited(to, card)
          end)
          table.insertTable(cards, table.filter(room.discard_pile, function(id)
            local card = Fk:getCardById(id)
            return card.sub_type == type and not to:isProhibited(to, card)
          end))
          if #cards > 0 then
            room:useCard({
              from = to.id,
              tos = {{to.id}},
              card = Fk:getCardById(table.random(cards)),
            })
          end
        end
      end
    elseif choice == "sk__huituo4" then
      room:handleAddLoseSkills(to, self.name, nil, true, false)
    end
  end,
}
local sk__xingshuai = fk.CreateTriggerSkill{
  name = "sk__xingshuai",
  anim_type = "masochism",
  events = {fk.Damaged},
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(self) and data.from and data.from ~= player and #player.room.alive_players > 1
  end,
  on_cost = function (self, event, target, player, data)
    local room = player.room
    local to = room:askForChoosePlayers(player, table.map(room:getOtherPlayers(player), Util.IdMapper), 1, 1,
      "#sk__xingshuai-choose", self.name)
    if #to > 0 then
      self.cost_data = to[1]
      return true
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local to = room:getPlayerById(self.cost_data)
    local choice = room:askForChoice(to, {"sk__xingshuai_turnover", "sk__xingshuai_extraturn:"..player.id}, self.name)
    if choice == "sk__xingshuai_turnover" then
      to:turnOver()
    else
      player:gainAnExtraTurn()
    end
  end,
}
Fk:addSkill(sk__huituo_active)
caorui:addSkill(sk__huituo)
caorui:addSkill(sk__xingshuai)
Fk:loadTranslationTable{
  ["sk__caorui"] = "曹叡",
  ["#sk__caorui"] = "",

  ["sk__huituo"] = "恢拓",
  [":sk__huituo"] = "准备阶段，你可以选择一名角色并选择一项（每局游戏每项限一次）：<br>1.令其回复体力至全场唯一最多；<br>"..
  "2.令其摸牌至全场唯一手牌数最多；<br>3.令其从牌堆或弃牌堆随机使用装备牌直到没有空置装备栏；<br>4.令其获得〖恢拓〗。",
  ["sk__xingshuai"] = "兴衰",
  [":sk__xingshuai"] = "当你受到其他角色造成的伤害后，你可以令一名其他角色选择一项：1.翻面；2.令你于此回合结束后进行一个额外回合。",
  ["#sk__huituo-invoke"] = "恢拓：你可以令一名角色执行一项（每局游戏每项限一次）",
  ["sk__huituo_active"] = "恢拓",
  ["sk__huituo1"] = "回复体力至全场唯一最多",
  ["sk__huituo2"] = "摸牌至全场唯一最多",
  ["sk__huituo3"] = "使用装备牌直到没有空置栏",
  ["sk__huituo4"] = "获得〖恢拓〗",
  ["#sk__xingshuai-choose"] = "兴衰：你可以指定一名其他角色，其选择翻面或令你获得一个额外回合",
  ["sk__xingshuai_turnover"] = "你翻面",
  ["sk__xingshuai_extraturn"] = "%src 获得一个额外回合",

  ["$sk__huituo1"] = "奕世重光，恢拓宏业。",
  ["$sk__huituo2"] = "重法明理，扬我大魏国威。",
  ["$sk__xingshuai1"] = "朝廷危亡，愿卿助我一臂之力。",
  ["$sk__xingshuai2"] = "国之兴衰，将军岂可坐视不理？",
  ["~sk__caorui"] = "大魏，如何托付……",
}

local sunxiu = General(extension, "sk__sunxiu", "wu", 3)
local sk__yanzhu = fk.CreateActiveSkill{
  name = "sk__yanzhu",
  anim_type = "control",
  card_num = 0,
  target_num = 1,
  prompt = "#sk__yanzhu",
  can_use = function(self, player)
    return player:usedSkillTimes(self.name, Player.HistoryPhase) < 3
  end,
  card_filter = Util.FalseFunc,
  target_filter =function (self, to_select, selected, selected_cards, card, extra_data, player)
    return #selected == 0
  end,
  on_use = function(self, room, effect)
    local player = room:getPlayerById(effect.from)
    local target = room:getPlayerById(effect.tos[1])
    room:addPlayerMark(target, "@sk__yanzhu", 1)
    local n = #table.filter(room.alive_players, function(p)
      return p:getMark("@sk__yanzhu") == target:getMark("@sk__yanzhu")
    end)
    if target:getMark("@sk__yanzhu") == 1 then
      target:drawCards(n, self.name)
    elseif target:getMark("@sk__yanzhu") == 2 then
      room:askForDiscard(target, n, n, true, self.name, false)
    elseif target:getMark("@sk__yanzhu") == 3 then
      room:damage({
        from = player,
        to = target,
        damage = n,
        skillName = self.name,
      })
    end
  end,
}
local sk__xingxue = fk.CreateTriggerSkill{
  name = "sk__xingxue",
  anim_type = "support",
  events = {fk.EventPhaseStart},
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(self) and player.phase == Player.Finish and
      table.find(player.room.alive_players, function(p)
        return p:getMark("@sk__yanzhu") > 0
      end)
  end,
  on_cost = function (self, event, target, player, data)
    local room = player.room
    local targets = table.map(table.filter(room.alive_players, function(p)
      return p:getMark("@sk__yanzhu") > 0
    end), Util.IdMapper)
    local to = room:askForChoosePlayers(player, targets, 1, 1, "#sk__xingxue-choose", self.name, true)
    if #to > 0 then
      self.cost_data = to[1]
      return true
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local to = room:getPlayerById(self.cost_data)
    to:drawCards(to:getMark("@sk__yanzhu"), self.name)
    if to ~= player and not to.dead and not player.dead and to:getHandcardNum() > to.maxHp then
      local n = to:getHandcardNum() - to.maxHp
      local cards = room:askForCard(to, n, n, false, self.name, false, ".", "#sk__xingxue-give:"..player.id.."::"..n)
      room:moveCardTo(cards, Card.PlayerHand, player, fk.ReasonGive, self.name, nil, false, to.id)
    end
    if not to.dead then
      room:setPlayerMark(to, "@sk__yanzhu", 0)
    end
  end,
}
sunxiu:addSkill(sk__yanzhu)
sunxiu:addSkill(sk__xingxue)
Fk:loadTranslationTable{
  ["sk__sunxiu"] = "孙休",
  ["#sk__sunxiu"] = "",

  ["sk__yanzhu"] = "宴诛",
  [":sk__yanzhu"] = "出牌阶段限三次，你可以令一名角色获得1枚“宴诛”标记，然后若其“宴诛”标记数为：<br>1，你令其摸标记数为1的角色数的牌；<br>"..
  "2，其弃置标记数为2的角色数的牌；<br>3，你对其造成标记数为3的角色数的伤害。",
  ["sk__xingxue"] = "兴学",
  [":sk__xingxue"] = "结束阶段，你可以令一名角色摸X张牌（X为其“宴诛”标记数），然后令其将超出体力上限的手牌交给你，弃置其所有“宴诛”标记。",
  ["#sk__yanzhu"] = "宴诛：令一名角色获得1枚“宴诛”标记，然后若其有1/2/3枚标记，其摸牌/弃牌/受到伤害",
  ["@sk__yanzhu"] = "宴诛",
  ["#sk__xingxue-choose"] = "兴学：令一名角色弃置所有标记，摸等量的牌，然后将超出体力上限的手牌交给你",
  ["#sk__xingxue-give"] = "兴学：请交给 %src %arg张手牌",

  ["$sk__yanzhu1"] = "设宴，以诛逆臣！",
  ["$sk__yanzhu2"] = "这就是，为你设下的鸿门宴！",
  ["$sk__xingxue1"] = "兴学，乃救国之道。",
  ["$sk__xingxue2"] = "昌明文教，仁政为民。",
  ["~sk__sunxiu"] = "内忧外患，心疾难医。",
}

local sundeng = General(extension, "sk__sundeng", "wu", 3)
local sk__kuangbi = fk.CreateTriggerSkill{
  name = "sk__kuangbi",
  anim_type = "support",
  events = {fk.AfterCardTargetDeclared},
  can_trigger = function(self, event, target, player, data)
    return player:hasSkill(self) and data.tos and (data.card.type == Card.TypeBasic or data.card:isCommonTrick()) and
      player:usedSkillTimes(self.name, Player.HistoryTurn) == 0
  end,
  on_cost = function(self, event, target, player, data)
    local room = player.room
    local targets = TargetGroup:getRealTargets(data.tos)
    table.insertTable(targets, room:getUseExtraTargets(data))
    room:setPlayerMark(player, "sk__kuangbi-tmp", targets)
    local _, dat = room:askForUseActiveSkill(player, "sk__kuangbi_active",
      "#sk__kuangbi-choose:::"..data.card:toLogString(), true, nil, false)
    room:setPlayerMark(player, "sk__kuangbi-tmp", 0)
    if dat then
      self.cost_data = dat
      return true
    end
  end,
  on_use = function(self, event, target, player, data)
    local tos = self.cost_data.targets
    player.room:sortPlayersByAction(tos)
    for _, id in ipairs(tos) do
      if table.contains(TargetGroup:getRealTargets(data.tos), id) then
        TargetGroup:removeTarget(data.tos, id)
      else
        table.insert(data.tos, {id})
      end
    end
  end,
}
local sk__kuangbi_active = fk.CreateActiveSkill{
  name = "sk__kuangbi_active",
  card_num = 0,
  min_target_num = 1,
  card_filter = Util.FalseFunc,
  target_filter =function (self, to_select, selected, selected_cards, card, extra_data, player)
    return table.contains(player:getMark("sk__kuangbi-tmp"), to_select)
  end,
}
Fk:addSkill(sk__kuangbi_active)
sundeng:addSkill(sk__kuangbi)
Fk:loadTranslationTable{
  ["sk__sundeng"] = "孙登",
  ["#sk__sundeng"] = "",

  ["sk__kuangbi"] = "匡弼",
  [":sk__kuangbi"] = "每回合限一次，当一名角色使用基本牌或普通锦囊牌指定目标时，你可以为此牌增加或减少任意个目标。",
  ["#sk__kuangbi-choose"] = "匡弼：你可以为此%arg增加或减少任意个目标",
  ["sk__kuangbi_active"] = "匡弼",

  ["$sk__kuangbi1"] = "成王之风，必有匡弼之益。",
  ["$sk__kuangbi2"] = "弼其良言，匡其恶行。",
  ["~sk__sundeng"] = "恳请陛下…用人唯才……咳咳咳……",
}

local zhuzhi = General(extension, "sk__zhuzhi", "wu", 4)
local sk__anguo = fk.CreateTriggerSkill{
  name = "sk__anguo",
  anim_type = "support",
  events = {fk.DrawNCards},
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(self) and data.n > 0
  end,
  on_cost = function(self, event, target, player, data)
    local room = player.room
    local to = room:askForChoosePlayers(player, table.map(room.alive_players, Util.IdMapper), 1, 1,
      "#sk__anguo-choose", self.name, true)
    if #to > 0 then
      self.cost_data = to[1]
      return true
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    data.n = data.n - 1
    local to = room:getPlayerById(self.cost_data)
    local yes = true
    while not to.dead and yes do
      local cards = table.filter(room.draw_pile, function(id)
        local card = Fk:getCardById(id)
        return card.type == Card.TypeEquip and not to:isProhibited(to, card)
      end)
      if #cards == 0 then return end
      local card = Fk:getCardById(table.random(cards))
      room:useCard{
        from = to.id,
        card = card,
      }
      if to.dead then return end
      if card.sub_type == Card.SubtypeWeapon then
        to:drawCards(card.attack_range, self.name)
        yes = false
      elseif card.sub_type == Card.SubtypeArmor or card.sub_type == Card.SubtypeTreasure then
        if to:isWounded() then
          room:recover{
            who = to,
            num = 1,
            recoverBy = player,
            skillName = self.name,
          }
        end
        yes = false
      else
        yes = true
      end
    end
  end,
}
zhuzhi:addSkill(sk__anguo)
Fk:loadTranslationTable{
  ["sk__zhuzhi"] = "朱治",
  ["#sk__zhuzhi"] = "",

  ["sk__anguo"] = "安国",
  [":sk__anguo"] = "摸牌阶段，你可以少摸一张牌，令一名角色随机使用牌堆中的一张装备牌，若此牌为：武器牌，其摸X张牌（X为此牌的攻击范围）；"..
  "防具牌或宝物牌，其回复1点体力；坐骑牌，其重复此流程。",
  ["#sk__anguo-choose"] = "安国：你可以少摸一张牌，令一名角色使用随机装备，根据类别执行额外效果",

  ["$sk__anguo1"] = "止戈休战，为安国之本。",
  ["$sk__anguo2"] = "尽毕生之力，保国泰民安。",
  ["~sk__zhuzhi"] = "不能再为王室分忧了……",
}

local wanglang = General(extension, "sk__wanglang", "wei", 3)
local sk__quanxiang = fk.CreateActiveSkill{
  name = "sk__quanxiang",
  anim_type = "offensive",
  card_num = 0,
  target_num = 1,
  prompt = "#sk__quanxiang",
  can_use = function(self, player)
    return not player:isKongcheng() and player:getMark("@@sk__quanxiang-phase") == 0
  end,
  card_filter = Util.FalseFunc,
  target_filter =function (self, to_select, selected, selected_cards, card, extra_data, player)
    return #selected == 0 and to_select ~= player.id and player:canPindian(Fk:currentRoom():getPlayerById(to_select))
  end,
  on_use = function(self, room, effect)
    local player = room:getPlayerById(effect.from)
    local target = room:getPlayerById(effect.tos[1])
    local pindian = player:pindian({target}, self.name)
    if pindian.results[target.id].winner == player then
      local n = target.hp
      if not player.dead then
        room:setPlayerMark(player, "@@sk__quanxiang-phase", 1)
      end
      if not target.dead then
        room:loseHp(target, n, self.name)
      end
      if not target.dead and target:isWounded() then
        room:recover({
          who = target,
          num = math.min(n, target:getLostHp()),
          recoverBy = player,
          skillName = self.name,
        })
      end
      if not player.dead then
        room:addPlayerMark(player, "@sk__wanglang_raoshe", 1)
      end
    else
      if not player.dead then
        room:addPlayerMark(player, "@sk__wanglang_raoshe", 2)
      end
    end
    if not player.dead and player:getMark("@sk__wanglang_raoshe") > 6 then
      room:killPlayer({who = player.id,})
    end
  end,
}
local sk__gushe = fk.CreateTriggerSkill{
  name = "sk__gushe",
  mute = true,
  frequency = Skill.Compulsory,
  events = {fk.PindianCardsDisplayed, fk.PindianResultConfirmed},
  can_trigger = function(self, event, target, player, data)
    if player:hasSkill(self) then
      if event == fk.PindianCardsDisplayed then
        return player == data.from or data.results[player.id]
      else
        self.cost_data = nil
        if data.winner and data.winner == player then
          if data.from == player then
            self.cost_data = data.toCard
          else
            self.cost_data = data.fromCard
          end
        else
          if data.from == player then
            self.cost_data = data.fromCard
          elseif data.to == player then
            self.cost_data = data.toCard
          end
        end
        return self.cost_data and player.room:getCardArea(self.cost_data) == Card.Processing
      end
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    player:broadcastSkillInvoke(self.name)
    room:notifySkillInvoked(player, self.name, "drawcard")
    local card = self.cost_data
    if event == fk.PindianCardsDisplayed then
      if player == data.from then
        card = data.fromCard
      elseif data.results[player.id] then
        card = data.results[player.id].toCard
      end
      card.number = math.min(card.number + player:getMark("@sk__wanglang_raoshe"), 13)
    else
      room:moveCardTo(card, Card.PlayerHand, player, fk.ReasonJustMove, self.name, nil, true, player.id)
    end
  end,
}
local sk__jici = fk.CreateTriggerSkill{
  name = "sk__jici",
  anim_type = "defensive",
  events = {fk.DamageInflicted},
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(self) and data.from and data.from ~= player and not data.from.dead
  end,
  on_cost = function(self, event, target, player, data)
    return player.room:askForSkillInvoke(player, self.name, nil, "#sk__jici-invoke::"..data.from.id)
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    room:doIndicate(player.id, {data.from.id})
    data.from:drawCards(1, self.name)
    if player.dead or data.from.dead or not player:canPindian(data.from) then return end
    local pindian = player:pindian({data.from}, self.name)
    if pindian.results[data.from.id].winner == player then
      return true
    else
      data.damage = math.min(data.damage, 1)
      if not player.dead then
        room:addPlayerMark(player, "@sk__wanglang_raoshe", 1)
        if player:getMark("@sk__wanglang_raoshe") > 6 then
          room:killPlayer({who = player.id,})
        end
      end
    end
  end
}
wanglang:addSkill(sk__quanxiang)
wanglang:addSkill(sk__gushe)
wanglang:addSkill(sk__jici)
Fk:loadTranslationTable{
  ["sk__wanglang"] = "王朗",
  ["#sk__wanglang"] = "",

  ["sk__quanxiang"] = "劝降",
  [":sk__quanxiang"] = "出牌阶段，你可以与一名角色拼点：若你赢，你令其失去所有体力，此技能本阶段失效，若其因此进入濒死状态且被救回，"..
  "你令其回复等量的体力，然后你获得1枚“饶舌”标记；若你没赢，你获得2枚“饶舌”标记。<br>（若你拥有7枚“饶舌”标记，你死亡）",
  ["sk__gushe"] = "鼓舌",
  [":sk__gushe"] = "锁定技，你的拼点牌点数+X（X为“饶舌”标记数）。当你拼点赢后，你获得对方的拼点牌；当你没赢后，你获得你的拼点牌。",
  ["sk__jici"] = "激词",
  [":sk__jici"] = "当你受到其他角色对你造成的伤害时，你可以令其摸一张牌，然后你与其拼点：若你赢，防止此伤害；若你没赢，将此伤害值改为1点，"..
  "然后你获得1枚“饶舌”标记。<br>（若你拥有7枚“饶舌”标记，你死亡）",
  ["#sk__quanxiang"] = "劝降：你可以拼点，若你赢，对方失去所有体力！",
  ["@sk__wanglang_raoshe"] = "饶舌",
  ["@@sk__quanxiang-phase"] = "劝降失效",
  ["#sk__jici-invoke"] = "激词：是否令 %dest 摸一张牌并与其拼点？若你赢，防止你受到的伤害；若没赢，伤害减至1并获得“饶舌”标记",

  ["$sk__quanxiang1"] = "来者可是诸葛孔明？",
  ["$sk__quanxiang2"] = "既知天命识时务，为何要兴无名之师？",
  ["$sk__gushe1"] = "你若倒戈卸甲，以礼来降，仍不失封侯之位。",
  ["$sk__gushe2"] = "国安民乐，岂不美哉？",
  ["$sk__jici1"] = "你……诸葛村夫，你敢？",
  ["$sk__jici2"] = "荒谬之言，荒谬之言！",
  ["~sk__wanglang"] = "你……你！呃啊……",
}

local sunliang = General(extension, "sk__sunliang", "wu", 3)
local sk__kuizhu = fk.CreateTriggerSkill{
  name = "sk__kuizhu",
  mute = true,
  frequency = Skill.Compulsory,
  events = {fk.EventPhaseStart},
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(self) and player.phase == Player.Finish
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    player:broadcastSkillInvoke(self.name)
    local n1, n2 = 0, 0
    room.logic:getEventsOfScope(GameEvent.MoveCards, 1, function(e)
      for _, move in ipairs(e.data) do
        if move.from and move.moveReason == fk.ReasonDiscard then
          if move.from == player.id then
            n2 = n2 + #move.moveInfo
          else
            n1 = n1 + #move.moveInfo
          end
        end
        return false
      end
    end, Player.HistoryTurn)
    if n1 > n2 then
      room:notifySkillInvoked(player, self.name, "offensive")
      local to = room:askForChoosePlayers(player, table.map(room.alive_players, Util.IdMapper), 1, 1, 
        "#sk__kuizhu-choose", self.name, false)
      room:damage({
        from = player,
        to = room:getPlayerById(to[1]),
        damage = 2,
        skillName = self.name,
      })
    else
      room:notifySkillInvoked(player, self.name, "drawcard")
      room:loseHp(player, 1, self.name)
      if not player.dead then
        player:drawCards(#room.alive_players, self.name)
      end
    end
  end,
}
local sk__chezheng = fk.CreateTriggerSkill{
  name = "sk__chezheng",
  anim_type = "control",
  events = {fk.EventPhaseEnd},
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(self) and player.phase == Player.Play and
      player:usedSkillTimes(self.name, Player.HistoryTurn) == 0
  end,
  on_cost = function(self, event, target, player, data)
    local _, dat = player.room:askForUseActiveSkill(player, "sk__chezheng_active",
      "#sk__chezheng-invoke:::"..player.hp, true, nil, false)
    if dat then
      self.cost_data = dat
      return true
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    room:sortPlayersByAction(self.cost_data.targets)
    local tos = {}
    local targets = table.map(self.cost_data.targets, Util.Id2PlayerMapper)
    for _, p in ipairs(targets) do
      if not p.dead then
        if self.cost_data.interaction == "sk__chezheng_discard" then
          room:askForDiscard(p, 1, 1, true, self.name, false, ".", "#sk__chezheng-discard")
        else
          p:drawCards(1, self.name)
        end
      end
      if not p.dead then
        table.insert(tos, p)
      end
    end
    tos = table.reverse(tos)
    for _, p in ipairs(tos) do
      if self.cost_data.interaction == "sk__chezheng_discard" then
        p:gainAnExtraPhase(Player.Play)
      else
        p:gainAnExtraPhase(Player.Discard)
      end
    end
  end,
}
local sk__chezheng_active = fk.CreateActiveSkill{
  name = "sk__chezheng_active",
  card_num = 0,
  min_target_num = 1,
  max_target_num = function()
    return Self.hp
  end,
  interaction = function()
    return UI.ComboBox {choices = {"sk__chezheng_discard", "sk__chezheng_draw"}}
  end,
  card_filter = Util.FalseFunc,
  target_filter =function (self, to_select, selected, selected_cards, card, extra_data, player)
    if #selected < player.hp then
      if self.interaction.data == "sk__chezheng_discard" then
        return not Fk:currentRoom():getPlayerById(to_select):isNude()
      else
        return true
      end
    end
  end,
}
Fk:addSkill(sk__chezheng_active)
sunliang:addSkill(sk__kuizhu)
sunliang:addSkill(sk__chezheng)
Fk:loadTranslationTable{
  ["sk__sunliang"] = "孙亮",
  ["#sk__sunliang"] = "",

  ["sk__kuizhu"] = "溃诛",
  [":sk__kuizhu"] = "锁定技，结束阶段，若所有其他角色于本回合内弃置的牌数之和大于你，你对一名角色造成2点伤害，否则你失去1点体力并摸X张牌"..
  "（X为存活角色数）。",
  ["sk__chezheng"] = "掣政",
  [":sk__chezheng"] = "每回合限一次，出牌阶段结束时，你可以选择一项：1.令至多X名角色各弃置一张牌，若如此做，这些角色于此阶段结束后，"..
  "依次执行一个额外出牌阶段；2.令至多X名角色各摸一张牌，若如此做，这些角色于此阶段结束后，依次执行一个额外弃牌阶段。（X为你的体力值）",
  ["#sk__kuizhu-choose"] = "溃诛：对一名角色造成2点伤害！",
  ["sk__chezheng_active"] = "掣政",
  ["#sk__chezheng-invoke"] = "掣政：你可以令至多%arg名角色弃牌/摸牌并执行额外的出牌阶段/弃牌阶段",
  ["sk__chezheng_discard"] = "弃一张牌，执行出牌阶段",
  ["sk__chezheng_draw"] = "摸一张牌，执行弃牌阶段",
  ["#sk__chezheng-discard"] = "掣政：请弃置一张牌，稍后将执行一个额外出牌阶段",

  ["$sk__kuizhu1"] = "朕虽年幼，亦能诛杀此权臣！",
  ["$sk__kuizhu2"] = "东吴之主，宁死不做朝堂傀儡，必殊死一搏！",
  ["$sk__chezheng1"] = "这大好的东吴江山，怎能落入他人之手？",
  ["$sk__chezheng2"] = "权臣当道，政权难掌啊。",
  ["~sk__sunliang"] = "机事不密，方至于此。",
}

local mayunlu = General(extension, "sk__mayunlu", "shu", 4, 4, General.Female)
local sk__fengyin = fk.CreateTriggerSkill{
  name = "sk__fengyin",
  anim_type = "drawcard",
  events = {fk.DamageCaused},
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(self) and data.to ~= player and data.card and
      ((data.card.trueName == "slash" and player:getMark("sk__fengyin_slash-turn") == 0) or
      (data.card.name == "duel" and player:getMark("sk__fengyin_duel-turn") == 0))
  end,
  on_cost = function(self, event, target, player, data)
    return player.room:askForSkillInvoke(player, self.name, nil, "#sk__fengyin-invoke::"..data.to.id)
  end,
  on_use = function(self, event, target, player, data)
    player.room:setPlayerMark(player, "sk__fengyin_"..data.card.trueName.."-turn", 1)
    local n1 = #table.filter(player:getCardIds("h"), function(id)
      if player:hasSkill("sk__rongzhuang") and #player:getEquipments(Card.SubtypeWeapon) > 0 and
        #player:getEquipments(Card.SubtypeArmor) > 0 then
        return Fk:getCardById(id).color == Card.Red
      else
        return Fk:getCardById(id).suit == Card.Diamond
      end
    end)
    local n2 = #table.filter(data.to:getCardIds("h"), function(id)
      if player:hasSkill("sk__rongzhuang") and #player:getEquipments(Card.SubtypeWeapon) > 0 and
        #player:getEquipments(Card.SubtypeArmor) > 0 then
        return Fk:getCardById(id).color == Card.Red
      else
        return Fk:getCardById(id).suit == Card.Diamond
      end
    end)
    if n1 > 0 then
      player:drawCards(n1, self.name)
    end
    if n2 > 0 then
      data.damage = data.damage + n2
    end
  end,
}
local sk__rongzhuang = fk.CreateTriggerSkill{
  name = "sk__rongzhuang",
  anim_type = "offensive",
  events = {fk.CardUsing},
  frequency = Skill.Compulsory,
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(self) and data.card.trueName == "slash" and
      #player:getEquipments(Card.SubtypeArmor) > 0
  end,
  on_use = function(self, event, target, player, data)
    data.disresponsiveList = table.map(player.room:getOtherPlayers(player), Util.IdMapper)
  end,
}
local sk__rongzhuang_targetmod = fk.CreateTargetModSkill{
  name = "#sk__rongzhuang_targetmod",
  main_skill = sk__rongzhuang,
  bypass_times = function(self, player, skill, scope)
    return player:hasSkill(sk__rongzhuang) and skill.trueName == "slash_skill" and scope == Player.HistoryPhase and
      #player:getEquipments(Card.SubtypeWeapon) > 0
  end,
}
sk__rongzhuang:addRelatedSkill(sk__rongzhuang_targetmod)
mayunlu:addSkill(sk__fengyin)
mayunlu:addSkill(sk__rongzhuang)
mayunlu:addSkill("mashu")
Fk:loadTranslationTable{
  ["sk__mayunlu"] = "马云騄",
  ["#sk__mayunlu"] = "关山凤吟",

  ["sk__fengyin"] = "凤吟",
  [":sk__fengyin"] = "每回合各限一次，当你使用【杀】或【决斗】对其他角色造成伤害时，你可以摸X张牌并令此伤害+Y（X为你手牌中的"..
  "<font color='red'>♦</font>牌数，Y为目标角色手牌中的<font color='red'>♦</font>牌数）。",
  ["sk__rongzhuang"] = "戎妆",
  [":sk__rongzhuang"] = "锁定技，若你的装备区里有：武器牌，你使用【杀】无次数限制；防具牌，你使用的【杀】不能被其他角色响应；"..
  "武器牌和防具牌，你将〖凤吟〗中的“<font color='red'>♦</font>牌”改为“红色牌”。",
  ["#sk__fengyin-invoke"] = "凤吟：是否对 %dest 发动“凤吟”，摸牌并增加伤害？",

  ["$sk__fengyin1"] = "战阵听凤吟，长枪踏山河。",
  ["$sk__fengyin2"] = "轻骑入敌阵，凤鸣破九霄。",
  ["$sk__rongzhuang1"] = "巾帼之志，戎马为妆。",
  ["$sk__rongzhuang2"] = "银枪映红妆，良骑载千金。",
  ["~sk__mayunlu"] = "子龙哥哥，你还会记得我吗……",
}

local zhongyao = General(extension, "sk__zhongyao", "wei", 3)
local sk__huomo = fk.CreateViewAsSkill{
  name = "sk__huomo",
  pattern = ".|.|.|.|.|basic",
  prompt = "#sk__huomo",
  interaction = function(self,player)
    local all_names = U.getAllCardNames("b")
    local names = U.getViewAsCardNames(player, self.name, all_names, {}, player:getTableMark("sk__huomo-turn"))
    if #names > 0 then
      return U.CardNameBox { choices = names, all_choices = all_names }
    end
  end,
  card_filter = function(self, to_select, selected)
    return #selected == 0 and Fk:getCardById(to_select).color == Card.Black
  end,
  view_as = function(self, cards)
    if #cards ~= 1 or not self.interaction.data then return end
    local card = Fk:cloneCard(self.interaction.data)
    card:addSubcards(cards)
    card.skillName = self.name
    return card
  end,
  before_use = function(self, player, use)
    local mark = player:getTableMark("sk__huomo-turn")
    table.insert(mark, Fk:cloneCard(self.interaction.data).trueName)
    player.room:setPlayerMark(player, "sk__huomo-turn", mark)
  end,
  enabled_at_play = Util.TrueFunc,
  enabled_at_response = function(self, player, response)
    return not response
  end,
}
local sk__dingguan = fk.CreateTriggerSkill{
  name = "sk__dingguan",
  anim_type = "support",
  events = {fk.TargetSpecified},
  can_trigger = function(self, event, target, player, data)
    return player:hasSkill(self) and target.phase == Player.Play and data.firstTarget and data.card.color == Card.Black and
      table.find(AimGroup:getAllTargets(data.tos), function(id)
        return not player.room:getPlayerById(id).dead
      end) and #player.room.logic:getActualDamageEvents(1, Util.TrueFunc, Player.HistoryPhase) == 0
  end,
  on_cost = function(self, event, target, player, data)
    local targets = table.filter(AimGroup:getAllTargets(data.tos), function(id)
      return not player.room:getPlayerById(id).dead
    end)
    local tos = player.room:askForChoosePlayers(player, targets, 1, 999, "#sk__dingguan-choose", self.name, true)
    if #tos > 0 then
      self.cost_data = tos
      return true
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    room:sortPlayersByAction(self.cost_data)
    for _, id in ipairs(self.cost_data) do
      local p = room:getPlayerById(id)
      if not p.dead then
        p:drawCards(1, self.name)
      end
    end
  end,
}
zhongyao:addSkill(sk__huomo)
zhongyao:addSkill(sk__dingguan)
Fk:loadTranslationTable{
  ["sk__zhongyao"] = "钟繇",
  ["#sk__zhongyao"] = "正书楷模",

  ["sk__huomo"] = "活墨",
  [":sk__huomo"] = "每回合每种牌名限一次，你可以将一张黑色牌当任意基本牌使用。",
  ["sk__dingguan"] = "定关",
  [":sk__dingguan"] = "当一名角色于其出牌阶段内使用黑色牌指定目标后，若本阶段内没有角色受到过伤害，你可以令其中任意个目标各摸一张牌。",
  ["#sk__huomo"] = "活墨：你可以将一张黑色牌当任意基本牌使用",
  ["#sk__dingguan-choose"] = "定关：你可以令其中任意个目标各摸一张牌",

  ["$sk__huomo1"] = "飞鸿戏海，舞鹤游天。",
  ["$sk__huomo2"] = "笔墨春秋，挥毫天地。",
  ["$sk__dingguan1"] = "关右既定，朝廷无西顾之忧。",
  ["$sk__dingguan2"] = "平定敌寇，民户殷实，再现汉武之世。",
  ["~sk__zhongyao"] = "笔墨不停，绢纸未尽，吾却休矣……",
}

local nanhualaoxian = General(extension, "sk__nanhualaoxian", "qun", 3)
local sk__xianshou = fk.CreateTriggerSkill{
  name = "sk__xianshou",
  anim_type = "support",
  events = {fk.TurnStart},
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(self)
  end,
  on_cost = function (self, event, target, player, data)
    local room = player.room
    local to = room:askForChoosePlayers(player, table.map(room.alive_players, Util.IdMapper), 1, 1,
      "#sk__xianshou-choose", self.name, true)
    if #to > 0 then
      self.cost_data = to[1]
      return true
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local to = room:getPlayerById(self.cost_data)
    if to:hasSkill("sk__tiandao", true) then
      local mark = to:getTableMark("@sk__tiandao")
      if #mark == 0 then
        mark = {1, 1, 1, 1}
      end
      local judge = {
        who = to,
        reason = self.name,
        pattern = ".|.|^spade",
      }
      room:judge(judge)
      if to.dead then return end
      if judge.card.suit == Card.Spade then
        local choices = {}
        for i = 1, 4, 1 do
          if mark[i] > 0 then
            table.insert(choices, i)
          end
        end
        if #choices == 0 then return end
        local n = table.random(choices)
        mark[n] = mark[n] - 1
      else
        local n = math.random(1,4)
        mark[n] = mark[n] + 1
      end
      room:setPlayerMark(to, "@sk__tiandao", mark)
    else
      room:handleAddLoseSkills(to, "sk__tiandao", nil, true, false)
    end
  end,
}
local sk__tiandao = fk.CreateTriggerSkill{
  name = "sk__tiandao",
  anim_type = "drawcard",
  frequency = Skill.Compulsory,
  events = {fk.EventPhaseStart},
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(self) and player.phase == Player.Start
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local mark = player:getTableMark("@sk__tiandao")
    if #mark == 0 then
      mark = {1, 1, 1, 1}
    end

    if mark[1] > 0 then
      player:drawCards(mark[1], self.name)
    end
    if player.dead then return end

    local n = mark[2]
    if n > 0 then
      local skills = {}
      for _, general in ipairs(room.general_pile) do
        local g = Fk.generals[general]
        if g.kingdom == "qun" then
          table.insertTableIfNeed(skills, g:getSkillNameList())
        end
      end
      skills = table.filter(skills, function(s)
        return not player:hasSkill(s, true)
      end)
      if #skills == 0 then return end
      local skill = table.random(skills, n)
      room:handleAddLoseSkills(player, skill, nil, true, false)
    end
    if player.dead then return end

    local n1, n2 = mark[3], mark[4]
    if n1 > 0 or n2 > 0 then
      local to = room:askForChoosePlayers(player, table.map(room.alive_players, Util.IdMapper), 1, 1,
        "#sk__tiandao-choose:::"..n1..":"..n2, self.name, true)
      if #to > 0 then
        to = room:getPlayerById(to[1])
        if n1 > 0 and not to:isNude() then
          local cards = table.random(to:getCardIds("he"), n1)
          room:throwCard(cards, self.name, to, to)
        end
        if n2 > 0 and not to.dead then
          room:damage({
            from = player,
            to = to,
            damage = n2,
            damageType = fk.ThunderDamage,
            skillName = self.name,
          })
        end
      end
    end
  end,

  refresh_events = {fk.EventAcquireSkill, fk.EventLoseSkill},
  can_refresh = function(self, event, target, player, data)
    return target == player and data == self
  end,
  on_refresh = function(self, event, target, player, data)
    local room = player.room
    if event == fk.EventAcquireSkill then
      room:setPlayerMark(player, "@sk__tiandao", {1, 1, 1, 1})
    elseif event == fk.EventLoseSkill then
      room:setPlayerMark(player, "@sk__tiandao" ,0)
    end
  end,
}
local sk__chengfeng = fk.CreateTriggerSkill{
  name = "sk__chengfeng",
  anim_type = "special",
  frequency = Skill.Compulsory,
  events = {fk.DamageInflicted, fk.TurnEnd},
  can_trigger = function(self, event, target, player, data)
    if event == fk.DamageInflicted then
      return target == player and player:hasSkill(self)
    elseif event == fk.TurnEnd then
      return player:hasSkill(self) and player:getMark("@sk__chengfeng") > 1
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    if event == fk.DamageInflicted then
      local judge = {
        who = player,
        reason = self.name,
        pattern = ".",
      }
      room:judge(judge)
      if player.dead then return end
      if judge.card.suit == Card.Spade then
        room:addPlayerMark(player, "@sk__chengfeng", 1)
      else
        data.damage = data.damage - 1
      end
    elseif event == fk.TurnEnd then
      room:removePlayerMark(player, "@sk__chengfeng", 2)
      player:gainAnExtraTurn(true)
    end
  end,
}
nanhualaoxian:addSkill(sk__xianshou)
nanhualaoxian:addSkill(sk__chengfeng)
nanhualaoxian:addRelatedSkill(sk__tiandao)
Fk:loadTranslationTable{
  ["sk__nanhualaoxian"] = "南华老仙",
  ["#sk__nanhualaoxian"] = "代天宣化",

  ["sk__xianshou"] = "仙授",
  [":sk__xianshou"] = "回合开始时，你可以选择一名角色，令其获得〖天道〗；若其已拥有〖天道〗，则改为判定：若结果不为♠，"..
  "你令其〖天道〗中的随机一项数字+1；若结果为♠，改为-1。",
  ["sk__chengfeng"] = "乘风",
  [":sk__chengfeng"] = "锁定技，当你受到伤害时，你判定：若结果不为♠，你令此伤害-1；若结果为♠，你获得1枚“乘风”标记。<br>一名角色的回合结束后，"..
  "若“乘风”标记不少于2枚，你弃置2枚“乘风”标记并执行一个额外回合。",
  ["sk__tiandao"] = "天道",
  [":sk__tiandao"] = "锁定技，准备阶段，你摸1张牌，随机获得武将牌堆中群势力武将的1个技能，然后你可以选择一名角色，令其随机弃置1张牌，"..
  "对其造成1点雷电伤害。",
  ["#sk__xianshou-choose"] = "仙授：令一名角色获得“天道”，或其根据判定结果修改“天道”",
  ["@sk__tiandao"] = "天道",
  ["#sk__tiandao-choose"] = "天道：选择一名角色，其随机弃置%arg张牌，你对其造成%arg2点雷电伤害",
  ["@sk__chengfeng"] = "乘风",

  ["$sk__xianshou1"] = "吾有天书三卷，汝可愿习之一二？",
  ["$sk__xianshou2"] = "汝得之，当代天宣化，普救世人。",
  ["$sk__chengfeng1"] = "承天地之正，御六气之辩，以游无穷。",
  ["$sk__chengfeng2"] = "扶摇而上九万里，绝云气，负青天。",
  --["$sk__tiandao1"] = "",
  --["$sk__tiandao2"] = "",
  ["~sk__nanhualaoxian"] = "至人无己，神人无功，圣人无名。",
}

local jiangwei = General(extension, "sk_sp__jiangwei", "wei", 5)
local sk__kunfen = fk.CreateTriggerSkill{
  name = "sk__kunfen",
  anim_type = "drawcard",
  frequency = Skill.Compulsory,
  events = {fk.Damaged, fk.HpLost, fk.MaxHpChanged},
  can_trigger = function(self, event, target, player, data)
    if target == player and player:hasSkill(self) then
      if event == fk.Damaged then
        return true
      else
        return data.num < 0
      end
    end
  end,
  on_use = function(self, event, target, player, data)
    player:drawCards(3, self.name)
    if player:usedSkillTimes(self.name, Player.HistoryTurn) == 1 and not player.dead and player:isWounded() then
      player.room:recover({
        who = player,
        num = 1,
        recoverBy = player,
        skillName = self.name,
      })
    end
  end,
}
local sk__caiyu = fk.CreateTriggerSkill {
  name = "sk__caiyu",
  anim_type = "special",
  events = {fk.EventPhaseStart},
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(self) and player.phase == Player.Start
  end,
  on_cost = function(self, event, target, player, data)
    return player.room:askForSkillInvoke(player, self.name, nil, "#sk__caiyu-invoke")
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    room:changeMaxHp(player, -1)
    if player.dead then return end
    local generals = {}
    for name, general in pairs(Fk.generals) do
      if general.package.extensionName ~= "hegemony" and
        table.find({"zhugeliang", "wolong"}, function(s)
          return name:endsWith(s)
        end) then
        table.insert(generals, general)
      end
    end
    if #generals == 0 then return end
    local skills = {}
    for _, general in ipairs(generals) do
      local list = general:getSkillNameList(true)
      for _, skill in ipairs(list) do
        if not player:hasSkill(skill, true) then
          table.insertIfNeed(skills, skill)
        end
      end
    end
    if #skills == 0 then return end
    room:handleAddLoseSkills(player, table.random(skills), nil, true, false)
  end,
}
jiangwei:addSkill(sk__kunfen)
jiangwei:addSkill(sk__caiyu)
Fk:loadTranslationTable{
  ["sk_sp__jiangwei"] = "姜维",
  ["#sk_sp__jiangwei"] = "幼麒",

  ["sk__kunfen"] = "困奋",
  [":sk__kunfen"] = "锁定技，当你受到伤害后、失去体力后或减少体力上限后，你摸三张牌；若是你本回合第一次发动此技能，你回复1点体力。",
  ["sk__caiyu"] = "才遇",
  [":sk__caiyu"] = "准备阶段，你可以减1点体力上限，随机获得一个诸葛亮、卧龙诸葛亮或神诸葛亮的技能。",
  ["#sk__caiyu-invoke"] = "才遇：你可以减1点体力上限，随机获得一个诸葛亮的技能！",
}

local huanghao = General(extension, "sk__huanghao", "shu", 3)
local sk__qinqing = fk.CreateTriggerSkill{
  name = "sk__qinqing",
  anim_type = "control",
  events = {fk.EventPhaseStart},
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(self) and player.phase == Player.Finish
  end,
  on_cost = function (self, event, target, player, data)
    local room = player.room
    local to = room:askForChoosePlayers(player, table.map(room.alive_players, Util.IdMapper), 1, 1,
      "#sk__qinqing-choose", self.name, true)
    if #to > 0 then
      self.cost_data = to[1]
      return true
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local to = room:getPlayerById(self.cost_data)
    for _, p in ipairs(room:getOtherPlayers(player)) do
      if to.dead then return end
      if not p.dead and p:inMyAttackRange(to) and not p:isNude() then
        local card = room:askForCard(p, 1, 1, true, self.name, false, ".", "#sk__qinqing-give::"..to.id)
        room:moveCardTo(card, Card.PlayerHand, to, fk.ReasonGive, self.name, nil, false, p.id)
      end
    end
    if not player.dead and not to.dead and player:getHandcardNum() >= to:getHandcardNum() and to:isWounded()
      and room:askForSkillInvoke(player, self.name, nil, "#sk__qinqing-recover::"..to.id) then
      room:recover({
        who = to,
        num = 1,
        recoverBy = player,
        skillName = self.name
      })
    end
  end,
}
local sk__huisheng = fk.CreateTriggerSkill{
  name = "sk__huisheng",
  events = {fk.DamageInflicted},
  anim_type = "defensive",
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(self) and not player:isKongcheng() and data.from and data.from ~= player
      and not data.from.dead
  end,
  on_cost = function(self, event, target, player, data)
    local room = player.room
    local cards = room:askForCard(player, 1, 3, true, self.name, true, ".", "#sk__huisheng-invoke::"..data.from.id)
    if #cards > 0 then
      self.cost_data = cards
      return true
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local cards = self.cost_data
    local n = #cards
    local get = room:askForCardChosen(data.from, player, {card_data = {{player.general, cards}}}, self.name)
    if #room:askForDiscard(data.from, n, n, true, self.name, true, ".",
      "#sk__huisheng-discard::"..player.id..":"..n..":"..Fk:getCardById(get, true):toLogString()) ~= n then
      room:moveCardTo(get, Card.PlayerHand, data.from, fk.ReasonPrey, self.name, nil, false, data.from.id)
      return true
    end
  end,
}
huanghao:addSkill(sk__qinqing)
huanghao:addSkill(sk__huisheng)
Fk:loadTranslationTable{
  ["sk__huanghao"] = "黄皓",
  ["#sk__huanghao"] = "便辟佞慧",

  ["sk__qinqing"] = "寝情",
  [":sk__qinqing"] = "结束阶段，你可以选择一名角色，令攻击范围内含有该角色的其他角色依次交给其一张牌，然后若该角色的手牌数不大于你，你可以"..
  "令其回复1点体力。",
  ["sk__huisheng"] = "贿生",
  [":sk__huisheng"] = "当你受到其他角色造成的伤害时，你可以选择至多三张手牌令其观看，其选择一项：1.获得其中一张牌，防止此伤害；2.弃置等量的牌。",
  ["#sk__qinqing-choose"] = "寝情：选择一名角色，攻击范围内含有其的其他角色依次交给其一张牌",
  ["#sk__qinqing-give"] = "寝情：请交给 %dest 一张牌",
  ["#sk__qinqing-recover"] = "寝情：是否令 %dest 回复1点体力？",
  ["#sk__huisheng-invoke"] = "贿生：你可以选择至多三张手牌，%dest 选择弃置等量的牌，或获得其中一张并防止对你造成的伤害",
  ["#sk__huisheng-discard"] = "贿生：弃置%arg张牌，否则你获得 %arg2 并防止对 %dest 造成的伤害",

  ["$sk__qinqing1"] = "陛下今日不理朝政，退下吧~",
  ["$sk__qinqing2"] = "陛下已就寝，此事改日再来传达。",
  ["$sk__huisheng1"] = "这些都是你的，只要保我平安~",
  ["$sk__huisheng2"] = "还望将军多美言几句。",
  ["~sk__huanghao"] = "啊……啊！魏军杀来了！",
}

local huaman = General(extension, "sk__huaman", "shu", 3, 3, General.Female)
local sk__manyi = fk.CreateTriggerSkill{
  name = "sk__manyi",
  anim_type = "drawcard",
  events = {fk.TargetSpecified, fk.TargetConfirmed},
  can_trigger = function(self, event, target, player, data)
    if target == player and player:hasSkill(self) and
      (data.card.trueName == "slash" or data.card:isCommonTrick()) and data.card.name ~= "savage_assault" then
      if event == fk.TargetSpecified then
        return true
      else
        return data.from ~= player.id
      end
    end
  end,
  on_cost = function (self, event, target, player, data)
    return player.room:askForSkillInvoke(player, self.name, nil, "#sk__manyi-invoke:::"..data.card:toLogString())
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room

    room:sendLog{
      type = "#SkChangeCardSkill",
      from = player.id,
      to = { data.from },
      arg = self.name,
      arg2 = data.card:toLogString(),
      arg3 = "savage_assault",
    }

    local use = room.logic:getCurrentEvent():findParent(GameEvent.UseCard, true)
    if use ~= nil then
      local new_card = Fk:cloneCard("savage_assault", data.card.suit, data.card.number)
      local c = table.simpleClone(data.card)
      for k, v in pairs(c) do
        if new_card[k] == nil then
          new_card[k] = v
        end
      end
      if data.card:isVirtual() then
        new_card.subcards = data.card.subcards
      else
        new_card.id = data.card.id
      end
      new_card.skillNames = data.card.skillNames
      new_card.skill = Fk.skills["savage_assault_skill"]
      data.card = new_card
      use.data[1].card = new_card
    end
    if not player.dead then
      player:drawCards(1, self.name)
    end
  end,
}
local sk__souying = fk.CreateTriggerSkill{
  name = "sk__souying",
  mute = true,
  events = {fk.CardRespondFinished},
  can_trigger = function(self, event, target, player, data)
    if player:hasSkill(self) then
      if data.card.trueName == "slash" then
        return table.find(player.room.alive_players, function(p)
          return not table.contains(player:getTableMark("sk__souying1-turn"), p.id)
        end)
      elseif data.card.trueName == "jink" then
        return table.find(player.room.alive_players, function(p)
          return not table.contains(player:getTableMark("sk__souying2-turn"), p.id) and p:isWounded()
        end)
      end
    end
  end,
  on_cost = function (self, event, target, player, data)
    local room = player.room
    local targets, n = {}, 1
    if data.card.trueName == "slash" then
      targets = table.map(table.filter(room.alive_players, function(p)
        return not table.contains(player:getTableMark("sk__souying1-turn"), p.id)
      end), Util.IdMapper)
    elseif data.card.trueName == "jink" then
      n = 2
      targets = table.map(table.filter(room.alive_players, function(p)
        return not table.contains(player:getTableMark("sk__souying1-turn"), p.id)
      end), Util.IdMapper)
    end
    local to = room:askForChoosePlayers(player, targets, 1, 1, "#sk__souying"..n.."-invoke", self.name, true)
    if #to > 0 then
      self.cost_data = {to[1], n}
      return true
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    player:broadcastSkillInvoke(self.name)
    local to = room:getPlayerById(self.cost_data[1])
    local n = self.cost_data[2]
    local mark = player:getTableMark("sk__souying"..n.."-turn")
    table.insertIfNeed(mark, to.id)
    room:setPlayerMark(player, "sk__souying"..n.."-turn", mark)
    if n == 1 then
      room:notifySkillInvoked(player, self.name, "offensive")
      room:damage({
        from = player,
        to = to,
        damage = 1,
        skillName = self.name,
      })
    else
      room:notifySkillInvoked(player, self.name, "support")
      if to:isWounded() then
        room:recover{
          who = to,
          num = 1,
          recoverBy = player,
          skillName = self.name
        }
      end
    end
  end,
}
huaman:addSkill(sk__manyi)
huaman:addSkill(sk__souying)
Fk:loadTranslationTable{
  ["sk__huaman"] = "花鬘",
  ["#sk__huaman"] = "沙场魅影",

  ["sk__manyi"] = "蛮裔",
  [":sk__manyi"] = "当你使用【杀】或普通锦囊牌指定目标后，或当你成为其他角色使用【杀】或普通锦囊牌的目标后，你可以将此牌的效果改为"..
  "【南蛮入侵】，然后摸一张牌。",
  ["sk__souying"] = "薮影",
  [":sk__souying"] = "每回合对每名角色各限一次，当一名角色打出【杀】后，你可以对一名角色造成1点伤害；当一名角色打出【闪】后，你可以令一名角色"..
  "回复1点体力。",
  ["#sk__manyi-invoke"] = "蛮裔：是否将此%arg的效果改为【南蛮入侵】并摸一张牌？",
  ["#sk__souying1-invoke"] = "薮影：你可以对一名角色造成1点伤害",
  ["#sk__souying2-invoke"] = "薮影：你可以令一名角色回复1点体力",

  ["$sk__manyi1"] = "蛮族天骄，裔延九黎！",
  ["$sk__manyi2"] = "灵犀为师，巨象为友。",
  ["$sk__souying1"] = "蛮女巾帼，自可以一当百。",
  ["$sk__souying2"] = "沙场倩影，只身险战不惧！",
  ["~sk__huaman"] = "蛮族之地，再无……安宁……",
}

local sp_pangtong = General(extension, "sk_sp__pangtong", "wu", 3)
local sk__guolun = fk.CreateTriggerSkill{
  name = "sk__guolun",
  anim_type = "control",
  events = {fk.AfterCardsMove, fk.HpRecover, fk.Damage},
  can_trigger = function(self, event, target, player, data)
    if player:hasSkill(self) then
      self.cost_data = {0, 0, 0, 0}
      if event == fk.AfterCardsMove then
        local n1, n2 = 0, 0
        for _, move in ipairs(data) do
          if move.moveReason == fk.ReasonDraw and move.toArea == Card.PlayerHand then
            if move.to == player.id or player:getMark("@sk__guolun") == "status3" or player:getMark("@sk__guolun") == "status4" then
              n1 = n1 + #move.moveInfo
            end
          end
          if move.moveReason == fk.ReasonDiscard then
            if move.from == player.id or player:getMark("@sk__guolun") == "status3" or player:getMark("@sk__guolun") == "status4" then
              for _, info in ipairs(move.moveInfo) do
                if info.fromArea == Card.PlayerHand or info.fromArea == Card.PlayerEquip then
                  n2 = n2 + 1
                end
              end
            end
          end
        end
        self.cost_data[1] = n1
        self.cost_data[2] = n2
      elseif player:getMark("@sk__guolun") == "status4" then
        if event == fk.HpRecover then
          self.cost_data[3] = data.num
        elseif event == fk.Damage and target then
          self.cost_data[4] = data.damage
        end
      end
      if #player.room.alive_players > 0 then
        if player:getMark("sk__guolun1-turn") == 0 then
          if self.cost_data[2] > 0 or self.cost_data[3] > 0 then
            return true
          elseif self.cost_data[1] > 0 then
            if table.find(player.room:getOtherPlayers(player), function (p)
              return not p:isNude()
            end) then
              return true
            end
          elseif self.cost_data[4] > 0 then
            if table.find(player.room:getOtherPlayers(player), function (p)
              return p:isWounded()
            end) then
              return true
            end
          end
        end
        if player:getMark("@sk__guolun") ~= 0 and player:getMark("sk__guolun2-turn") == 0 then
          if self.cost_data[1] > 0 or self.cost_data[4] > 0 then
            return true
          elseif self.cost_data[2] > 0 then
            if table.find(player.room:getOtherPlayers(player), function (p)
              return not p:isNude()
            end) then
              return true
            end
          elseif self.cost_data[3] > 0 then
            if table.find(player.room:getOtherPlayers(player), function (p)
              return p:isWounded()
            end) then
              return true
            end
          end
        end
      end
    end
  end,
  on_trigger = function(self, event, target, player, data)
    if event == fk.AfterCardsMove then
      for _, move in ipairs(data) do
        if not player:hasSkill(self) or
          (player:getMark("@sk__guolun") == 0 and player:getMark("sk__guolun1-turn") > 0) or
          (player:getMark("@sk__guolun") ~= 0 and player:getMark("sk__guolun1-turn") > 0 and player:getMark("sk__guolun2-turn") > 0)
        then return end
        local n1, n2 = 0, 0
        if move.moveReason == fk.ReasonDraw and move.toArea == Card.PlayerHand then
          if move.to == player.id or player:getMark("@sk__guolun") == "status3" or player:getMark("@sk__guolun") == "status4" then
            n1 = n1 + #move.moveInfo
          end
        end
        if move.moveReason == fk.ReasonDiscard then
          if move.from == player.id or player:getMark("@sk__guolun") == "status3" or player:getMark("@sk__guolun") == "status4" then
            for _, info in ipairs(move.moveInfo) do
              if info.fromArea == Card.PlayerHand or info.fromArea == Card.PlayerEquip then
                n2 = n2 + 1
              end
            end
          end
        end
        if n1 > 0 then
          if (player:getMark("sk__guolun1-turn") == 0 and table.find(player.room:getOtherPlayers(player), function (p)
            return not p:isNude()
          end)) or
            (player:getMark("@sk__guolun") ~= 0 and player:getMark("sk__guolun2-turn") == 0) then
            self:doCost(event, target, player, {1, n1})
          end
        end
        if n2 > 0 then
          if player:getMark("sk__guolun1-turn") == 0 or
            (player:getMark("@sk__guolun") ~= 0 and player:getMark("sk__guolun2-turn") == 0 and
            table.find(player.room:getOtherPlayers(player), function (p)
              return not p:isNude()
            end)) then
            self:doCost(event, target, player, {2, n2})
          end
        end
      end
    elseif event == fk.HpRecover then
      if player:getMark("sk__guolun1-turn") == 0 or
        (player:getMark("@sk__guolun") ~= 0 and player:getMark("sk__guolun2-turn") == 0 and
        table.find(player.room:getOtherPlayers(player), function (p)
          return p:isWounded()
        end)) then
        self:doCost(event, target, player, {3, data.num})
      end
    elseif event == fk.Damage and target then
      if (player:getMark("sk__guolun1-turn") == 0 and table.find(player.room:getOtherPlayers(player), function (p)
        return p:isWounded()
      end)) or
        (player:getMark("@sk__guolun") ~= 0 and player:getMark("sk__guolun2-turn") == 0) then
        self:doCost(event, target, player, {4, data.damage})
      end
    end
  end,
  on_cost = function(self, event, target, player, data)
    local room = player.room
    local prompt
    if player:getMark("@sk__guolun") == 0 then
      if data[1] == 1 then
        prompt = 2
      else
        prompt = 1
      end
    else
      local choices, all_choices = {}, {}
      if data[1] == 1 or data[1] == 3 then
        table.insert(all_choices, "sk__guolun_"..(data[1] + 1)..":::"..data[2])
        if player:getMark("sk__guolun1-turn") == 0 then
          table.insert(choices, "sk__guolun_"..(data[1] + 1)..":::"..data[2])
        end
      else
        table.insert(all_choices, "sk__guolun_"..(data[1] - 1)..":::"..data[2])
        if player:getMark("sk__guolun1-turn") == 0 then
          table.insert(choices, "sk__guolun_"..(data[1] - 1)..":::"..data[2])
        end
      end
      if player:getMark("@sk__guolun") ~= 0 then
        table.insert(all_choices, "sk__guolun_"..data[1]..":::"..data[2])
        if player:getMark("sk__guolun2-turn") == 0 then
          table.insert(choices, "sk__guolun_"..data[1]..":::"..data[2])
        end
      end
      local choice
      if #choices == 1 then
        choice = choices[1]
      else
        table.insert(all_choices, "Cancel")
        table.insert(choices, "Cancel")
        choice = room:askForChoice(player, choices, self.name, nil, false, all_choices)
        if choice == "Cancel" then return end
      end
      prompt = tonumber(choice[12])
    end
    local targets = table.map(room:getOtherPlayers(player), Util.IdMapper)
    if prompt == 2 then
      targets = table.map(table.filter(room:getOtherPlayers(player), function(p)
        return not p:isNude()
      end), Util.IdMapper)
    elseif prompt == 3 then
      targets = table.map(table.filter(room:getOtherPlayers(player), function(p)
        return p:isWounded()
      end), Util.IdMapper)
    end
    local to = room:askForChoosePlayers(player, targets, 1, 1,
      "#sk__guolun"..prompt.."-choose:::"..data[2], self.name, true, false)
    if #to > 0 then
      self.cost_data = {to[1], prompt, data[2]}
      if prompt ~= data[1] then
        room:setPlayerMark(player, "sk__guolun1-turn", 1)
      else
        room:setPlayerMark(player, "sk__guolun2-turn", 1)
      end
      return true
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local to = room:getPlayerById(self.cost_data[1])
    local n = self.cost_data[3]
    if self.cost_data[2] == 1 then
      to:drawCards(n, self.name)
    elseif self.cost_data[2] == 2 then
      room:askForDiscard(to, n, n, true, self.name, false)
    elseif self.cost_data[2] == 3 then
      room:recover({
        who = to,
        num = math.min(n, to:getLostHp()),
        recoverBy = player,
        skillName = self.name,
      })
    elseif self.cost_data[2] == 4 then
      room:damage{
        from = player,
        to = to,
        damage = n,
        skillName = self.name,
      }
    end
  end,
}
local sk__songsang = fk.CreateTriggerSkill{
  name = "sk__songsang",
  anim_type = "drawcard",
  frequency = Skill.Compulsory,
  events = {fk.Death},
  can_trigger = function(self, event, target, player, data)
    return player:hasSkill(self.name)
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    if player:getMark("@sk__guolun") == 0 then
      room:setPlayerMark(player, "@sk__guolun", "status2")
    else
      local n = tonumber(player:getMark("@sk__guolun")[7])
      if n < 4 then
        room:setPlayerMark(player, "@sk__guolun", "status"..(n + 1))
      end
    end
    player:drawCards(#room.alive_players, self.name)
  end,
}
sp_pangtong:addSkill(sk__guolun)
sp_pangtong:addSkill(sk__songsang)
Fk:loadTranslationTable{
  ["sk_sp__pangtong"] = "庞统",
  ["#sk_sp__pangtong"] = "南州冠冕",

  ["sk__guolun"] = "过论",
  [":sk__guolun"] = "每回合限一次，当你摸牌或弃牌后，你可以令一名其他角色执行相反的效果。<br>"..
  "<font color='grey'><strong>二级</strong>：效果增加“可以令一名其他角色执行相同的效果”，每回合各限一次。<br>"..
  "<strong>三级</strong>：时机修改为“当任意一名角色摸牌或弃牌后”。<br>"..
  "<strong>四级</strong>：时机增加“回复体力或造成伤害后”。</font>",
  ["sk__songsang"] = "送丧",
  [":sk__songsang"] = "锁定技，当其他角色死亡时，你修改〖过论〗（至多三次）并摸X张牌（X为存活角色数）。",
  ["sk__guolun_1"] = "令一名角色摸%arg张牌",
  ["sk__guolun_2"] = "令一名角色弃%arg张牌",
  ["sk__guolun_3"] = "令一名角色回复%arg点体力",
  ["sk__guolun_4"] = "对一名角色造成%arg点伤害",
  ["#sk__guolun1-choose"] = "过论：你可以令一名角色摸%arg张牌",
  ["#sk__guolun2-choose"] = "过论：你可以令一名角色弃置%arg张牌",
  ["#sk__guolun3-choose"] = "过论：你可以令一名角色回复%arg点体力",
  ["#sk__guolun4-choose"] = "过论：你可以对一名角色造成%arg点伤害",
  ["@sk__guolun"] = "过论",
  ["status4"] = "四阶",

  ["$sk__guolun1"] = "",
  ["$sk__guolun2"] = "",
  ["$sk__songsang1"] = "送丧至江东，吾使命已尽。",
  ["$sk__songsang2"] = "",
  ["~sk_sp__pangtong"] = "终究不得东吴赏识。",
}

local lvdai = General(extension, "sk__lvdai", "wu", 4)
local sk__qinguo = fk.CreateActiveSkill{
  name = "sk__qinguo",
  anim_type = "support",
  card_num = 1,
  target_num = 1,
  prompt = "#sk__qinguo",
  card_filter = function(self, to_select, selected)
    return #selected == 0 and Fk:getCardById(to_select).type == Card.TypeEquip and
      Fk:currentRoom():getCardArea(to_select) ~= Card.PlayerEquip
  end,
  target_filter =function (self, to_select, selected, selected_cards, card, extra_data, player)
    return #selected == 0 and #selected_cards == 1 and
      not player:isProhibited(Fk:currentRoom():getPlayerById(to_select), Fk:getCardById(selected_cards[1]))
  end,
  on_use = function(self, room, effect)
    local player = room:getPlayerById(effect.from)
    local target = room:getPlayerById(effect.tos[1])
    room:useCard({
      from = player.id,
      tos = {{target.id}},
      card = Fk:getCardById(effect.cards[1]),
    })
  end,
}
local sk__qinguo_trigger = fk.CreateTriggerSkill{
  name = "#sk__qinguo_trigger",
  mute = true,
  main_skill = sk__qinguo,
  events = {fk.CardUseFinished, fk.AfterCardsMove},
  can_trigger = function(self, event, target, player, data)
    if player:hasSkill(sk__qinguo) then
      if event == fk.CardUseFinished then
        return target == player and data.card.type == Card.TypeEquip
      elseif event == fk.AfterCardsMove and player:getMark("sk__qinguo-turn") == 0 then
        local cards = {}
        for _, move in ipairs(data) do
          if move.from and move.toArea == Card.DiscardPile then
            for _, info in ipairs(move.moveInfo) do
              if info.fromArea == Card.PlayerEquip then
                table.insertIfNeed(cards, info.cardId)
              end
            end
          end
        end
        cards = U.moveCardsHoldingAreaCheck(player.room, cards)
        if #cards > 0 then
          self.cost_data = cards
          return true
        end
      end
    end
  end,
  on_cost = function(self, event, target, player, data)
    local room = player.room
    if event == fk.CardUseFinished then
      if player:getMark("sk__qinguo_cards") == 0 then
        room:setPlayerMark(player, "sk__qinguo_cards", U.getUniversalCards(room, "b"))
      end
      local success, dat = player.room:askForUseActiveSkill(player, "sk__qinguo_viewas", "#sk__qinguo-use", true,
        {bypass_times = true})
      if success then
        self.cost_data = dat
        return true
      end
    else
      local cards, choice = U.askforChooseCardsAndChoice(player, self.cost_data, {"OK"}, "sk__qinguo", "#sk__qinguo-prey",
        {"get_all", "Cancel"})
      if #cards > 0 then
        self.cost_data = cards
        return true
      elseif choice == "get_all" then
        self.cost_data = self.cost_data
        return true
      end
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    if event == fk.CardUseFinished then
      local dat = table.simpleClone(self.cost_data)
      local card = Fk:cloneCard(Fk:getCardById(dat.cards[1]).name)
      card.skillName = self.name
      room:useCard{
        from = player.id,
        tos = table.map(dat.targets, function(id) return {id} end),
        card = card,
        extraUse = true,
      }
    else
      room:setPlayerMark(player, "sk__qinguo-turn", 1)
      room:moveCardTo(self.cost_data, Card.PlayerHand, player, fk.ReasonJustMove, "sk__qinguo", nil, true, player.id)
    end
  end,
}
local sk__qinguo_viewas = fk.CreateViewAsSkill{
  name = "sk__qinguo_viewas",
  card_num = 1,
  expand_pile = function(self,player)
    return player:getTableMark("sk__qinguo_cards")
  end,
  card_filter = function(self, to_select, selected,player)
    return #selected == 0 and table.contains(player:getTableMark("sk__qinguo_cards"), to_select) and
      player:canUse(Fk:getCardById(to_select), {bypass_times = true})
  end,
  view_as = function(self, cards)
    if #cards ~= 1 then return end
    local card = Fk:cloneCard(Fk:getCardById(cards[1]).name)
    card.skillName = "sk__qinguo"
    return card
  end,
}
sk__qinguo:addRelatedSkill(sk__qinguo_trigger)
Fk:addSkill(sk__qinguo_viewas)
lvdai:addSkill(sk__qinguo)
Fk:loadTranslationTable{
  ["sk__lvdai"] = "吕岱",
  ["#sk__lvdai"] = "清身奉公",

  ["sk__qinguo"] = "勤国",
  [":sk__qinguo"] = "出牌阶段，你可以对任意角色使用装备牌。当你使用装备牌后，你可以视为使用任意一张基本牌。每回合限一次，"..
  "当一名角色装备区内的牌进入弃牌堆后，你可以获得之。",
  ["#sk__qinguo"] = "勤国：你可以对任意角色使用装备牌",
  ["#sk__qinguo_trigger"] = "勤国",
  ["sk__qinguo_viewas"] = "勤国",
  ["#sk__qinguo-use"] = "勤国：你可以视为使用一张基本牌",
  ["#sk__qinguo-prey"] = "勤国：你可以获得这些牌",
}

local wangyuanji = General(extension, "sk__wangyuanji", "qun", 3, 3, General.Female)
wangyuanji.subkingdom = "jin"
local sk__qianchong = fk.CreateTriggerSkill{
  name = "sk__qianchong",
  anim_type = "control",
  events = {fk.TurnEnd},
  can_trigger = function(self, event, target, player, data)
    if player:hasSkill(self) then
      local choices = {}
      if #player.room.logic:getEventsOfScope(GameEvent.UseCard, 2, function(e)
        local use = e.data[1]
        return use.from == player.id and use.card.color == Card.Red
      end, Player.HistoryTurn) == 1 then
        table.insert(choices, 1)
      end
      if #player.room.logic:getEventsOfScope(GameEvent.UseCard, 2, function(e)
        local use = e.data[1]
        return use.from == player.id and use.card.color == Card.Black
      end, Player.HistoryTurn) == 1 then
        table.insert(choices, 2)
      end
      if #choices > 0 then
        self.cost_data = choices
        return true
      end
    end
  end,
  on_cost = function(self, event, target, player, data)
    local room = player.room
    local prompt = "#sk__qianchong1-choose"
    if #self.cost_data == 1 then
      prompt = "#sk__qianchong"..self.cost_data[1].."-choose"
    end
    local to = room:askForChoosePlayers(player, table.map(room.alive_players, Util.IdMapper), 1, 1, prompt, self.name, true)
    if #to > 0 then
      if #self.cost_data == 2 then
        self.cost_data = {tos = to, dat = 1, extra = true}
      else
        self.cost_data = {tos = to, dat = self.cost_data[1]}
      end
      return true
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local to = room:getPlayerById(self.cost_data.tos[1])
    if self.cost_data.dat == 1 then
      local choices = {"sk__qianchong_draw"}
      if to:isWounded() then
        table.insert(choices, 1, "sk__qianchong_recover")
      end
      local choice = room:askForChoice(player, choices, self.name, "#sk__qianchong-choice::"..to.id)
      if choice == "sk__qianchong_recover" then
        room:recover({
          who = to,
          num = math.min(2, to:getLostHp()),
          recoverBy = player,
          skillName = self.name,
        })
      else
        to:drawCards(to.maxHp, self.name)
      end
    else
      local choices = {"sk__qianchong_loseHp"}
      if not to:isNude() then
        table.insert(choices, "sk__qianchong_discard")
      end
      local choice = room:askForChoice(player, choices, self.name, "#sk__qianchong-choice::"..to.id)
      if choice == "sk__qianchong_loseHp" then
        room:loseHp(to, 2, self.name)
      else
        room:askForDiscard(to, to.maxHp, to.maxHp, true, self.name, false)
      end
    end
    local yes = false
    if not player.dead and self.cost_data.extra then
      to = room:askForChoosePlayers(player, table.map(room.alive_players, Util.IdMapper), 1, 1,
        "#sk__qianchong2-choose", self.name, true)
      if #to > 0 then
        yes = true
        to = room:getPlayerById(to[1])
        local choices = {"sk__qianchong_loseHp"}
        if not to:isNude() then
          table.insert(choices, "sk__qianchong_discard")
        end
        local choice = room:askForChoice(player, choices, self.name, "#sk__qianchong-choice::"..to.id)
        if choice == "sk__qianchong_loseHp" then
          room:loseHp(to, 2, self.name)
        else
          room:askForDiscard(to, to.maxHp, to.maxHp, true, self.name, false)
        end
      end
    end
    if not player.dead and yes and not target:insideExtraTurn() then
      player:gainAnExtraTurn(true, self.name)
    end
  end,
}
local sk__shangjian = fk.CreateTriggerSkill{
  name = "sk__shangjian",
  anim_type = "support",
  frequency = Skill.Compulsory,
  events = {fk.EventPhaseStart, fk.EventPhaseEnd},
  can_trigger = function(self, event, target, player, data)
    if target == player and player.phase == Player.Discard then
      if event == fk.EventPhaseStart then
        return player:hasSkill(self) and player:getHandcardNum() > player:getMaxCards() and #player.room.alive_players > 1
      else
        return player:getMark("sk__shangjian-phase") > 0
      end
    end
  end,
  on_use = function(self, event, target, player, data)
    if event == fk.EventPhaseStart then
      local room = player.room
      local n = player:getHandcardNum() - player:getMaxCards()
      room:setPlayerMark(player, "sk__shangjian-phase", n)
      room:askForYiji(player, player:getCardIds("h"), room:getOtherPlayers(player), self.name, n, n,
        "#sk__shangjian-give:::"..n)
    else
      player:drawCards(player:getMark("sk__shangjian-phase"), self.name)
    end
  end,
}
wangyuanji:addSkill(sk__qianchong)
wangyuanji:addSkill(sk__shangjian)
Fk:loadTranslationTable{
  ["sk__wangyuanji"] = "王元姬",
  ["#sk__wangyuanji"] = "文明皇后",

  ["sk__qianchong"] = "谦冲",
  [":sk__qianchong"] = "一名角色回合结束时，若你于本回合：<br>"..
  "使用的红色牌数为1，你可以令一名角色回复2点体力或摸其体力上限张牌；<br>"..
  "使用的黑色牌数为1，你可以令一名角色失去2点体力或弃置其体力上限张牌；<br>"..
  "以上两项均执行，且本回合不为额外回合，你于本回合结束后执行一个额外回合。",
  ["sk__shangjian"] = "尚俭",
  [":sk__shangjian"] = "锁定技，弃牌阶段开始时，你将超过手牌上限数量的手牌任意分配给其他角色，然后此阶段结束时摸等量的牌。",
  ["#sk__qianchong1-choose"] = "谦冲：你可以令一名角色回复2点体力或摸其体力上限张牌",
  ["#sk__qianchong2-choose"] = "谦冲：你可以令一名角色失去2点体力或弃置其体力上限张牌",
  ["#sk__qianchong-choice"] = "谦冲：选择令 %dest 执行的一项",
  ["sk__qianchong_recover"] = "回复2点体力",
  ["sk__qianchong_draw"] = "其摸体力上限张牌",
  ["sk__qianchong_loseHp"] = "失去2点体力",
  ["sk__qianchong_discard"] = "其弃置体力上限张牌",
  ["#sk__shangjian-give"] = "尚俭：请将%arg张手牌分配给其他角色",
}

local zhangchangpu = General(extension, "sk__zhangchangpu", "wei", 3, 3, General.Female)
local sk__yanjiao = fk.CreateActiveSkill{
  name = "sk__yanjiao",
  anim_type = "support",
  min_card_num = 1,
  target_num = 1,
  prompt = function (self)
    return "#sk__yanjiao"..self.interaction.data
  end,
  interaction = function(self,player)
    local choices = {}
    for i = 1, 5, 1 do
      if not table.contains(player:getTableMark("sk__yanjiao-phase"), i) then
        table.insert(choices, tostring(i))
      end
    end
    return UI.ComboBox {choices = choices}
  end,
  card_filter = function(self, to_select, selected,player)
    if #selected < tonumber(self.interaction.data) and table.contains(player:getCardIds("h"), to_select) then
      if self.interaction.data == "1" then
        return table.every(player:getCardIds("h"), function (id)
          return Fk:getCardById(to_select).number >= Fk:getCardById(id).number
        end)
      elseif self.interaction.data == "2" then
        if #selected == 0 then
          return true
        else
          return Fk:getCardById(to_select).number == Fk:getCardById(selected[1]).number
        end
      elseif self.interaction.data == "3" then
        if #selected == 0 then
          return Fk:getCardById(to_select).suit ~= Card.NoSuit
        else
          return Fk:getCardById(to_select).suit == Fk:getCardById(selected[1]).suit
        end
      elseif self.interaction.data == "4" then
        if #selected == 0 then
          return true
        else
          return Fk:getCardById(to_select).number ~= Fk:getCardById(selected[1]).number
        end
      elseif self.interaction.data == "5" then
        if #selected == 0 then
          return Fk:getCardById(to_select).suit ~= Card.NoSuit
        else
          return Fk:getCardById(to_select).number ~= Fk:getCardById(selected[1]).number and
            Fk:getCardById(to_select).suit == Fk:getCardById(selected[1]).suit
        end
      end
    end
  end,
  target_filter =function (self, to_select, selected, selected_cards, card, extra_data, player)
    return #selected == 0 and to_select ~= player.id
  end,
  feasible = function (self, selected, selected_cards)
    if #selected == 1 and #selected_cards == tonumber(self.interaction.data) then
      if tonumber(self.interaction.data) < 4 then
        return true
      else
        local nums = table.map(selected_cards, function (id)
          return Fk:getCardById(id).number
        end)
        table.sort(nums, function (a, b)
          return a < b
        end)
        return nums[#nums] - nums[1] + 1 == tonumber(self.interaction.data)
      end
    end
  end,
  on_use = function(self, room, effect)
    local player = room:getPlayerById(effect.from)
    local target = room:getPlayerById(effect.tos[1])
    local n = tonumber(self.interaction.data)
    room:addTableMark(player, "sk__yanjiao-phase", n)
    room:moveCardTo(effect.cards, Card.PlayerHand, target, fk.ReasonGive, self.name, nil, false, player.id)
    if not player.dead then
      player:drawCards(n, self.name)
    end
    if not player.dead and not target.dead and player:getMark("@@sk__xingshen") > 0 and
      room:askForSkillInvoke(player, self.name, nil, "#sk__yanjiao-damage::"..target.id..":"..n) then
        room:doIndicate(player.id, {target.id})
        room:damage({
          from = player,
          to = target,
          damage = n,
          skillName = self.name,
        })
    end
  end,
}
local sk__xingshen = fk.CreateTriggerSkill{
  name = "sk__xingshen",
  anim_type = "masochism",
  frequency = Skill.Compulsory,
  events = {fk.Damaged},
  on_trigger = function(self, event, target, player, data)
    self.cancel_cost = false
    for i = 1, data.damage do
      if self.cancel_cost or not player:hasSkill(self) then break end
      self:doCost(event, target, player, data)
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    player:drawCards(2, self.name)
    if not player.dead and player:getMark("@@sk__xingshen") == 0 then
      if player:isWounded() then
        room:recover{
          who = player,
          num = 1,
          recoverBy = player,
          skillName = self.name,
        }
      end
      if not player.dead then
        room:setPlayerMark(player, "@@sk__xingshen", 1)
      end
    end
  end,

  refresh_events = {fk.AfterTurnEnd},
  can_refresh = function(self, event, target, player, data)
    return target == player and player:getMark("@@sk__xingshen") > 0
  end,
  on_refresh = function(self, event, target, player, data)
    player.room:setPlayerMark(player, "@@sk__xingshen", 0)
  end,
}
zhangchangpu:addSkill(sk__yanjiao)
zhangchangpu:addSkill(sk__xingshen)
Fk:loadTranslationTable{
  ["sk__zhangchangpu"] = "张昌蒲",
  ["#sk__zhangchangpu"] = "严明训教",

  ["sk__yanjiao"] = "严教",
  [":sk__yanjiao"] = "出牌阶段每项各限一次，你可以将满足条件的X张手牌交给一名其他角色，然后摸X张牌（X为对应项的序号）：<br>"..
  "1：点数最大的牌；<br>"..
  "2：点数相同的牌；<br>"..
  "3：花色相同的牌；<br>"..
  "4：点数连续的牌；<br>"..
  "5：花色相同且点数连续的牌。<br>"..
  "当其他角色以此法获得牌后，若你有“省身”标记，你可以对其造成X点伤害。",
  ["sk__xingshen"] = "省身",
  [":sk__xingshen"] = "锁定技，当你受到1点伤害后，你摸两张牌，然后若你未拥有“省身”标记，你回复1点体力，并获得1枚“省身”标记直到你下个回合结束。",
  ["#sk__yanjiao1"] = "严教：将1张点数最大的手牌交给一名角色，摸等量的牌",
  ["#sk__yanjiao2"] = "严教：将2张点数相同的手牌交给一名角色，摸等量的牌",
  ["#sk__yanjiao3"] = "严教：将3张花色相同的手牌交给一名角色，摸等量的牌",
  ["#sk__yanjiao4"] = "严教：将4张点数连续的手牌交给一名角色，摸等量的牌",
  ["#sk__yanjiao5"] = "严教：将5张花色相同且点数连续的手牌交给一名角色，摸等量的牌",
  ["#sk__yanjiao-damage"] = "严教：是否对 %dest 造成%arg点伤害？",
  ["@@sk__xingshen"] = "省身",
}

local xingdaorong = General(extension, "sk__xingdaorong", "qun", 5)
local xuhe = fk.CreateTriggerSkill{
  name = "sk__xuhe",
  mute = true,
  frequency = Skill.Compulsory,
  events = {fk.CardUsing},
  can_trigger = function(self, event, target, player, data)
    if player:hasSkill(self) and data.tos then
      if target == player then
        return not player:isWounded() and table.find(TargetGroup:getRealTargets(data.tos), function (id)
          return id ~= player.id
        end)
      else
        return player:isWounded() and table.contains(TargetGroup:getRealTargets(data.tos), player.id)
      end
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    player:broadcastSkillInvoke(self.name)
    data.disresponsiveList = data.disresponsiveList or {}
    if target == player then
      room:notifySkillInvoked(player, self.name, "offensive")
      table.insertTable(data.disresponsiveList, table.map(room:getOtherPlayers(player), Util.IdMapper))
    else
      room:notifySkillInvoked(player, self.name, "negative")
      table.insertIfNeed(data.disresponsiveList, player.id)
    end
    if player:getMark("sk__xuhe-turn") == 0 then
      local n = #TargetGroup:getRealTargets(data.tos)
      if room:askForSkillInvoke(player, self.name, nil, "#sk__xuhe-draw:::"..n) then
        room:setPlayerMark(player, "sk__xuhe-turn", 1)
        player:drawCards(n, self.name)
      end
    end
  end,
}
xingdaorong:addSkill(xuhe)
Fk:loadTranslationTable{
  ["sk__xingdaorong"] = "邢道荣",
  ["#sk__xingdaorong"] = "零陵上将",

  ["sk__xuhe"] = "虚猲",
  [":sk__xuhe"] = "锁定技，若你未受伤，你使用的牌不能被其他角色响应；若你已受伤，你不能响应其他角色对你使用的牌。每回合限一次，当你触发此技能后，"..
  "你可以摸X张牌（X为触发此技能的牌的目标数）。",
  ["#sk__xuhe-draw"] = "虚猲：是否摸%arg张牌？",
}

return extension

